<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px">
      <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-s-promotion"></i>后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>相册列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="100"></el-table-column>
      <el-table-column prop="name" label="姓名" width="180"></el-table-column>
      <el-table-column prop="description" label="描述"></el-table-column>
      <el-table-column prop="sort" label="排序" width="100"></el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
        <el-button type="primary" class="el-icon-edit" circle size="mini" @click="handEdit(scope.row)"></el-button>
        <el-button type="danger" class="el-icon-delete" circle size="mini"  @click="open(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
export default {
  data() {
    return {
      tableData: []
    };
  },
  methods:{
    loadAlbumList(){
      let url = "http://172.233.5.142:9080/album/list";
      console.log("url="+url);
      this.axios.get(url).then((response)=>{
        let responseBody = response.data;
          this.tableData = responseBody.data;
      })
    },
    handEdit(album){

    },
    open(album){
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.handDelete(album);
        }).catch(() => {
        });
    },
    handDelete(album){
      let url = "http://172.233.5.142:9080/album/delete";
      console.log("url="+url);
      let formData = 'id='+album.id;
      this.axios.post(url,formData).then((response)=>{
        let responseBody = response.data;
        if(responseBody.state === 200){
          this.loadAlbumList();
        }else{
          //this.$message.error(responseBody.message);
          this.$alert(responseBody.message, '消息提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadAlbumList();
            }
          });
        }

      })

    },
  },
  mounted(){
    console.log("mounted");
    this.loadAlbumList();
  }
}
</script>

<style scoped>

</style>